﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO;

namespace SerializationStudy
{
    class ObjectReference
    {
        public static void Test()
        {
            using (MemoryStream stream = new MemoryStream())
            {
                var formater = new BinaryFormatter();
                formater.Serialize(stream, new TestClassC());

                stream.Position = 0;

                var test = formater.Deserialize(stream);

                Console.WriteLine(test);
            }
        }
    }

    [Serializable]
    public class TestClassC : IObjectReference
    {
        public object GetRealObject(StreamingContext context)
        {
            return "变成字符串了";
        }
    }
}
